<?php

namespace Biz\model\store;

use Doraemon\pockets\datebase\BaseDbModel;

class StoreAskAnswer extends BaseDbModel
{
    const _CONFIG_FILE_ = 'db_store';

    const _CONFIG_SELECT_ = 'db_store';

    const _DATABASE_ = 'store';

    const _TABLE_NAME = 'store_ask_answer';

    const STATUS_NORMAL = 1;//正常状态
    const STATUS_DEL = 9;//删除状态

    public static function getListByWhere($where, $field = '*')
    {
        $where['answer_status'] = self::STATUS_NORMAL;
        return self::select($field, $where);
    }

    public static function add($data)
    {
        if (!isset($data['answer_status'])) {
            $data['answer_status'] = self::STATUS_NORMAL;
        }
        if (!isset($data['addtime'])) {
            $data['addtime'] = date('Y-m-d H:i:s');
        }
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $result = self::insert($data)->rowCount();
        if ($result) {
            return self::id();
        }

        return false;
    }

    public static function updateData($data, $where)
    {
        if (!isset($data['edittime'])) {
            $data['edittime'] = date('Y-m-d H:i:s');
        }
        $ret = self::update($data, $where);
        if ($ret->errorCode() !== '00000') {
            return false;
        }
        return true;
    }

    public static function getInfoById($id)
    {
        return self::get('*', ['id' => $id]);
    }

    public static function getCount($where)
    {
        $where['answer_status'] = self::STATUS_NORMAL;
        return self::count($where);
    }


}